#pragma once

#include "../../plugin/base/framework.hh"
#include "../../corelib/singleton.hpp"

// User implemented framework
// @see Framework
class GatewayFramework : public Framework {
    using PathSessionMap = std::unordered_map<PathID, SessionID>;
    PathSessionMap pathSessionMap_; // { Path ID, Session ID}
    std::uint32_t maxBufferredMsgCount_; // Max bufferred message count for client
    constexpr static std::uint32_t DEFAULT_MAX_BUFFERRED_MSG_COUNT = 64;

public:
    GatewayFramework();
    virtual ~GatewayFramework();
    virtual bool onStart(kconfig::Config* config) override;
    virtual bool onStop() override;
    virtual void onTick(std::time_t millionseconds) override;
    virtual void onPathJoin(PathID pathID, SiteType siteType, UserData userData) override;
    virtual void onPathDisjoin(PathID pathID, SiteType siteType) override;
    virtual void onPathData(PathID pathID, SiteType siteType, std::uint32_t msgID,
        const char* data, std::size_t size) override;
    virtual void onSessionJoin(SessionID sessionID) override;
    virtual void onSessionDisjoin(SessionID sessionID) override;
    virtual void onSessionData(SessionID sessionID, std::uint32_t msgID, const char* data,
        std::size_t size) override;

public:
    std::uint32_t getMaxBufferredMsgCount() const;
};

// singleton of user framework
// NOTICE the name 'FrameworkRef' MUST NOT change
#define FrameworkRef (*kratos::corelib::Singleton<GatewayFramework>::instance())
